const util = require('../../utils/util.js');

Page({
  data: {
    schoolbase:{},
    teacherlist:[],
    lessonlist:[],
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    currentTab: '0',
    lessoninfo: {},
    schoolid: 0
  },
  onLoad: function (e) {
    this.getschoolinfo(e);
    // this.getindexlessonlist();
  },
  getschoolinfo: function (e) {
    let that = this;
    let schoolid = e.id
    util.request('school/getschoolinfo',{school_id:e.id}).then(function (res) {
      //console.log(res.data.bannerlist);
      if (res.errno === 0) {
        that.setData({
          schoolbase: res.data.schoolbase,
          teacherlist: res.data.teacherlist,
          lessonlist: res.data.lessonlist,
          schoolid: schoolid
        });
      }
    });
  },
  changeTab(e) {
    console.log(e.currentTarget.dataset.id)
    this.setData({
      tabIndex: e.currentTarget.dataset.id
    })
  },
  toSearch() {
    wx.navigateTo({
      url: '/pages/search/search'
    })
  },
  navigateClick(e) {
    console.log(e.currentTarget.dataset.url)
    wx.navigateTo({
      url: e.currentTarget.dataset.url
    })
  },
  boutiqueTo(e) {
    wx.navigateTo({
      url: '/pages/special/special'
    })
  },
  toLessoninfo(e) {
    //console.log(e.currentTarget.dataset.id);
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/lessoninfo/lessoninfo?id=${id}`
    })
  },
  goClasslist(e) {
    console.log(e.currentTarget.dataset.title);
    let title = e.currentTarget.dataset.title;
    let classid = e.currentTarget.dataset.classid;
    wx.navigateTo({
      url: '/pages/classlist/classlist?title=' + title + '&classid=' + classid
    })
  },
  toteacherdetails(e) {
    let id = e.currentTarget.dataset.id;
    let schoolid = e.currentTarget.dataset.schoolid;
    if (id & schoolid) {
      wx.navigateTo({
        url: `/pages/teacherdetails/teacherdetails?id=${id}`
      })
    }
  },
  onShareAppMessage: function (res) {
    let that = this
    return {
      title: that.data.schoolbase.school_name,
      path: 'pages/schooldetails/schooldetails?id=' + that.data.schoolid,
      imageUrl: that.data.schoolbase.imgurl || 'http://p8pho5rm4.bkt.clouddn.com/sharelogo_new.png'
    }
  }
})